# !/usr/bin/env python
# coding: utf8

import pygtk
from manager.bean_store      import *
pygtk.require('2.0')
import gtk
'''
Created on 28 mai 2009

@author: tmeedendorp
'''


class ThematicsStore(gtk.ListStore):
    
    def __init__(self, thematicNameList):
        gtk.ListStore.__init__(self, str, 'gboolean')
        self.categoriesTreeDic = {}
        for thematicName in thematicNameList:
            self.append([thematicName,True])    
            self.categoriesTreeDic[thematicName] = CategoriesTree(getBean("configurationManager").getThematicCategories(thematicName))              
                    
class CategoriesStore(gtk.ListStore):   
    def __init__(self, categoryNameList):
        gtk.ListStore.__init__(self, str, 'gboolean')
        self.filtersTreeDic = {}
        for categoryName in categoryNameList:
            self.append([categoryName,True])
            self.filtersTreeDic[categoryName] = FiltersTree(getBean("configurationManager").getCategoryFilters(categoryName))  
            
class FiltersStore(gtk.ListStore): 
    def __init__(self, filtersList):
        gtk.ListStore.__init__(self, str, 'gboolean')
        for filter in filtersList:
            self.append([filter,True])     

class AbstractThematicTree(gtk.TreeView):

    def __init__(self, listStore, name):
        gtk.TreeView.__init__(self, listStore)
        
        #name column
        self.nameColumn = gtk.TreeViewColumn(name)
        self.append_column(self.nameColumn)
        self.nameCell = gtk.CellRendererText()
        self.nameCell.set_property('editable', True)
        self.nameColumn.pack_start(self.nameCell, True)
        self.nameColumn.add_attribute(self.nameCell, 'text', 0)
        
        #enabled column
        self.enabledColumn = gtk.TreeViewColumn('Activé')
        self.append_column(self.enabledColumn)
        self.enabledCell = gtk.CellRendererToggle()
        self.enabledCell.set_property('activatable', True)
        self.enabledColumn.pack_start(self.enabledCell, True)
        self.enabledColumn.add_attribute(self.enabledCell, 'active', 1)
        
        self.set_search_column(0)
        
       
class ThematicsTree(AbstractThematicTree):

    def __init__(self, thematicNameList):
        self.thematicsStore = ThematicsStore(thematicNameList)
        AbstractThematicTree.__init__(self, self.thematicsStore, 'Thématiques')


                        
class CategoriesTree(AbstractThematicTree):

    def __init__(self, categoryNameList):
        self.categoriesStore = CategoriesStore(categoryNameList)
        AbstractThematicTree.__init__(self, self.categoriesStore, 'Catégories')


class FiltersTree(AbstractThematicTree):

    def __init__(self, filterList):
        self.filtersStore = FiltersStore(filterList)
        AbstractThematicTree.__init__(self, self.filtersStore, 'Filtres')
        



